﻿using WRJClient.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WRJClient.UI.Map;
using Esri.ArcGISRuntime.Geometry;
using WRJClient.Utils;
using WRJClient.Common;

namespace WRJClient.ViewModel
{
    public class AirlineViewModel : BaseViewModel<AirlineModel>, IMapObject
    {
        private BaseGraphic _gBody = new BaseGraphic();
        public BaseGraphic GBody { get { return _gBody; } }
        public bool Visable { get { return _gBody.IsVisible; }
            set
            {
                _gBody.IsVisible = value;
            }
        }

        public bool IsEnabled { get { return ArcgisUtils.IsExtentValid(_gBody.Geometry.Extent); } }

        public AirlineViewModel(AirlineModel model = null) : base(model)
        {
            _gBody.IsVisible = false;

            InitGraphics();
        }

        public bool IsVisable
        {
            get { return _gBody.IsVisible; }
            set { if (_gBody.IsVisible != value) { _gBody.IsVisible = value; OnPropertyChanged(); }; }
        }

        public void InitGraphics()
        {
            PointCollection pointCollection = ArcCommon.PointCollectionFromGeoPointJson(StaticData.Waypoints);
            GraphicFactory.CreateLineGraphic(_gBody, StaticData.DbId, GraphicPart.Base, SymbolHelper.Instance.GetLineSymbolInfo(GetType(), "航线"), pointCollection);
        }

        public void AddGraphics()
        {
            MapManager.Instance.AddGraphic("Layer2", _gBody);
        }
        public void RemoveGraphics()
        {
            MapManager.Instance.RemoveGraphic("Layer2", _gBody);
        }
    }
}
